﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Images
{
    public class Image:IImage
    {
        public void AddImage(Model.Image image, ref Model.NutriLeafDBEntities context)
        {
            context.Images.AddObject(image);
            context.SaveChanges();
        }

        public void RemoveImage(int id, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.Images.Where(p => p.ImageID == id).First());
            context.SaveChanges();
        }

        public void RemoveImage(Model.Image image, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.Images.Where(p => p.ImageID == image.ImageID).First());
            context.SaveChanges();
        }

        public Model.Image GetImage(int id, ref Model.NutriLeafDBEntities context)
        {
            return context.Images.Where(p => p.ImageID == id).First();
        }

        public void Update(Model.Image image, ref Model.NutriLeafDBEntities context)
        {
            Model.Image img = context.Images.Where(p => p.ImageID == image.ImageID).First();
            img = image;
            context.SaveChanges();
        }

        public string GetImageFile(int id, ref Model.NutriLeafDBEntities context)
        {
            return context.Images.Where(p => p.ImageID == id).First().ImageFile;
        }
    }
}